<?php
namespace Home\Model;
use Think\Model;

class PaymentsHistoryModel extends Model {
	//写入明细
	public function writePayments($data){
		
	}

	//获取某用户明细列表
	public function getPaymentsList($uid=null,$page=1,$pagesize=20){
		if(empty($uid)) return null;
		if($page < 1 || !is_numeric($page)) $page = 1;
		if($pagesize < 1 || !is_numeric($pagesize)) $pagesize = 20;
		
		// $where['uid'] = $uid;
		$where['_string'] = '(from_uid='.$uid.' AND payments_type=-1) OR (to_uid='.$uid.' AND payments_type=1)';
		$offset = ($page-1)*$pagesize;
		$count = $this->where($where)->count();
		
		$list = $this->where($where)->limit($offset.",".$pagesize)->order('id desc')->select();

		$return['total_page'] = ceil($count/$pagesize);
		$return['current_page'] = $page;
		$return['data'] = $list;

		return $return;
	}
	
}

?>